package com.example;

import org.junit.Test;

/**
 * @ClassName SimpleTest
 * @Description 数组桶
 * @Author: XMK
 * @Date: 2021/5/11 10:17
 * @Version: 1.0
 */
public class SimpleTest {

    @Test
    public void test3() {
        int oldCapacity = 15;
        int newCapacity = oldCapacity + (oldCapacity >> 1);

        System.out.println(newCapacity);

    }

    @Test
    public void leftMove() {

        System.out.println(1 << 0);
        System.out.println(Integer.toBinaryString(1 << 0));
        System.out.println(1 << 2);
        System.out.println(Integer.toBinaryString(1 << 2));
        System.out.println(1 << 3);
        System.out.println(Integer.toBinaryString(1 << 3));
        System.out.println(1 << 4);
        System.out.println(Integer.toBinaryString(1 << 4));

        System.out.println(~(1 << 4));
        System.out.println(Integer.toBinaryString(~(1 << 4)));
        System.out.println(1 << 2  & ~(1 << 4));
        System.out.println(Integer.toBinaryString(1 << 2 & ~(1 << 4)));
    }

    @Test
    public void test4() {
        System.out.println(((4<<1) - (4>>>1)) + " ----2*4*0.75 " + (2*4*0.75));
    }

    // 数组桶
    // //i处结点数量，2: TreeBin或链表结点数, 其它：链表结点数。主要用于每次加入结点后查看是否要由链表转为红黑树
    @Test
    public void tes3() {
        System.out.println(Integer.toBinaryString(1));
        System.out.println(Integer.toBinaryString(-1));
        System.out.println(Integer.toBinaryString(2));
        System.out.println(Integer.toBinaryString(-2));
        System.out.println(Integer.toBinaryString(2*2*2));
        System.out.println(Integer.toBinaryString(2*2*2+1));
        System.out.println(Integer.toBinaryString(-2*2*2));
        System.out.println(Integer.toBinaryString(-2*2*2+1));
        System.out.println(Integer.toBinaryString(-2*2*2+2));
        System.out.println(Integer.toBinaryString(-2*2*2-1));
        System.out.println(Integer.toBinaryString(-2*2*2-2));


        System.out.println("--------------------");
        System.out.println(Integer.toBinaryString(1));
        System.out.println((1 << 1) + " binary: " + Integer.toBinaryString(1 << 1));
        System.out.println((1 << 2) + " binary: " + Integer.toBinaryString(1 << 2));
        System.out.println((1 << 3) + " binary: " + Integer.toBinaryString(1 << 3));
        System.out.println((1 << 4) + " binary: " + Integer.toBinaryString(1 << 4));
        System.out.println((1 << 5) + " binary: " + Integer.toBinaryString(1 << 5));
        System.out.println((1 << 15) + " binary: " + Integer.toBinaryString(1 << 15));
        System.out.println((1 << 16) + " binary: " + Integer.toBinaryString(1 << 16));
        System.out.println("--------------------");
        System.out.println(1 + " 高位多少个0：" + Integer.numberOfLeadingZeros(1) + " binary: " + Integer.toBinaryString(Integer.numberOfLeadingZeros(1)));
        System.out.println(2 + " 高位多少个0：" + Integer.numberOfLeadingZeros(2) + " binary: " + Integer.toBinaryString(Integer.numberOfLeadingZeros(2)));
        System.out.println(2*2 + " 高位多少个0：" + Integer.numberOfLeadingZeros(2*2) + " binary: " + Integer.toBinaryString(Integer.numberOfLeadingZeros(2*2)));
        System.out.println(2*2*2 + " 高位多少个0：" + Integer.numberOfLeadingZeros(2*2*2) + " binary: " + Integer.toBinaryString(Integer.numberOfLeadingZeros(2*2*2)));
        System.out.println(2*2*2*2 + " 高位多少个0：" + Integer.numberOfLeadingZeros(2*2*2*2) + " binary: " + Integer.toBinaryString(Integer.numberOfLeadingZeros(2*2*2*2)));
    }

    @Test
    public void test2() {
        System.out.println(Integer.numberOfLeadingZeros(0));
        System.out.println(Integer.numberOfLeadingZeros(1));
        System.out.println(Integer.numberOfLeadingZeros(2));
        System.out.println(Integer.numberOfLeadingZeros(2*2));
        System.out.println(Integer.numberOfLeadingZeros(2*2*2));
        System.out.println(Integer.numberOfLeadingZeros(2*2*2*2));

    }

    @Test
    public void test1() {

        String s = "中国";
        System.out.println(s.length());
        System.out.println(s.getBytes().length);
    }

}
